package com.urbanski.clipboard.server.util;

import com.urbanski.clipboard.common.exception.InvalidCommandException;
import com.urbanski.clipboard.server.action.command.EndActionHandler;
import com.urbanski.clipboard.server.action.command.ExitActionHandler;
import com.urbanski.clipboard.server.action.command.InfoActionHandler;
import com.urbanski.clipboard.server.action.command.KickActionHandler;
import com.urbanski.clipboard.server.action.command.ServerActionHandler;

public class ServerConstants
{
	private ServerConstants()
	{
	}
	
	public static enum ServerCommand
	{
		EXIT("exit", ExitActionHandler.class), KICK("kick", KickActionHandler.class), END("end", EndActionHandler.class), INFO("info", InfoActionHandler.class);

		private String keyword;
		private Class<? extends ServerActionHandler> actionHandler;

		private ServerCommand(String keyword, Class<? extends ServerActionHandler> actionHandler)
		{
			this.keyword = keyword;
			this.actionHandler = actionHandler;
		}

		public String getKeyword()
		{
			return keyword;
		}

		public Class<? extends ServerActionHandler> getActionHandler()
		{
			return actionHandler;
		}

		public String toString()
		{
			return keyword;
		}

		public static ServerCommand getClientCommand(String keyword) throws InvalidCommandException
		{
			for (ServerCommand command : ServerCommand.values())
			{
				if (command.keyword.equals(keyword))
				{
					return command;
				}
			}

			throw new InvalidCommandException("Invalid command entered: " + keyword);
		}
	}
}
